﻿@{
    ViewBag.Title = "档案借阅";
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
    var listColumns = ViewBag.Columns as List<SGArchiveSystem7x.Models.CColumnsModel>;
}
<table id="Insiders_BrrArchive_grid" class="easyui-datagrid" style="width:100%;" title="借阅" data-options="
       rownumbers:true,
       singleSelect:true,
       autoRowHeight:false,
       pagination:true,
       fitColumns:true,
       fit:true,
       striped:true,
       checkOnSelect:false,
       selectOnCheck:false,
       toolbar:'#Insiders_BrrArchive_tb',
       pageSize:@SGArchiveSystem7x.Models.CCommonsModels.PageSize,
      pageList:[10,15,20],
       collapsible:false">
    <thead frozen="true">
        <tr>
            @{foreach (var c in listColumns)
                {
                    if (c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
    <thead>
        <tr>
            @{foreach (var c in listColumns)
                {
                    if (!c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
</table>
<div id="Insiders_BrrArchive_tb" style="padding:2px 5px;">
    <input type="text" class="easyui-textbox" label="借阅人姓名:" labelalign="right" labelwidth="80px" style="width:150px" id="Insiders_BrrArchive_txtUSERNAME" />
    <select class="easyui-combobox" label="利用目的:" labelwidth="60px" labelalign="right" style="width:150px;" id="Insiders_BrrArchive_cmbLYMD" editable="false" panelHeight="auto">
        @{
            List<SGArchiveSystem7x.Models.CComboboxModel> listLYMD = ViewBag.LYMD as List<SGArchiveSystem7x.Models.CComboboxModel>;
            foreach (var n in listLYMD)
            {
                <option value="@n.ID">@n.Text</option>
            }
        }
    </select>
    <select class="easyui-combobox" label="出库时间:" labelwidth="60px" labelalign="right" style="width:150px;" id="Insiders_BrrArchive_cmbCKSJ" editable="false" panelHeight="auto">
        <option value="1">1小时内</option>
        <option value="2">2小时内</option>
        <option value="3">当天</option>
        <option value="4" selected="selected">忽略</option>
    </select>
    <input type="text" class="easyui-datebox" data-options="editable:false" label="预计归还时间:" labelwidth="90px" labelalign="right" style="width:200px" id="Insiders_BrrArchive_txtYJGHTime" />
    <a href="javascript:void(0);" id="Insiders_BrrArchive_btnAppre" class="easyui-linkbutton button-blue" iconCls="icon-redo" onclick="App()" style="width:110px;height:30px;">申请</a>
</div>
<script>

    function Del(dh)
    {
        $.ajax({
            url: '/Insiders/Del_BrrSession',
            type: 'post',
            async: true,
            dataType: 'text',
            data: { 'dh': dh  },
            success: function (data) {
                $('#Insiders_BrrArchive_grid').datagrid('options').url = '/Insiders/Get_ajaxBrrArchive';
                $('#Insiders_BrrArchive_grid').datagrid('load');
             }
           });
    }
    $(document).ready(function () {
        $('#Insiders_BrrArchive_grid').datagrid({
            url: '/Insiders/Get_ajaxBrrArchive',
            singleSelect: true,
            method: 'post',
            onLoadSuccess: function (data) {
                $('.pagination-page-list').hide();
            }
        });
    });

      function tab(date1, date2) {
        var oDate1 = new Date(date1);
        var oDate2 = new Date(date2);
        if (oDate1.getTime() >= oDate2.getTime()) {
            return false;//第一大
        } else {
            return true;//第二大
        }
    }
    //获取当前日期yyyy-mm-dd
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    }
    function App()
    {
        var entities = [];
        var rows = $('#Insiders_BrrArchive_grid').datagrid('getRows');
        if (rows.length == 0) {
            $.messager.alert('提示！', '无申请的档案!', 'info');
            return false;
        }
        else {
            for (i = 0; i < rows.length; i++) {
                entities.push(rows[i]);
            }
            if ($('#Insiders_BrrArchive_txtYJGHTime').datebox('getValue') == "") {
                $.messager.alert('提示！', '请选择要归还时间!', 'info');
                return false;
            }
            else if ($('#Insiders_BrrArchive_txtUSERNAME').val() == "") {
                $.messager.alert('提示！', '必须输入借阅人姓名!', 'info');
                return false;
            }
            else {
                var lymd = "";

                var yjtime = $('#Insiders_BrrArchive_txtYJGHTime').datebox('getValue');
                 var date = getNowFormatDate();//当前日期
                if (tab(yjtime, date)) {
                $.messager.alert('提示', '选择日期小于当前日期!!');
                return false;
                   }
                if ($('#Insiders_BrrArchive_cmbLYMD').combobox("getText") == "其它") {
                    $.messager.prompt('提示', '请输入借阅目的', function (r) {
                        if (r) {
                            lymd = r;
                            $.ajax({
                                url: '/Insiders/Add_Brr',
                                type: 'post',
                                dataType: 'text',
                                data: {
                                    'entities': JSON.stringify(entities), 'type': @ViewBag.type, 'lymdid': $('#Insiders_BrrArchive_cmbLYMD').combobox("getValue"), 'lymd': lymd, 'YJGUTime':
                                        yjtime, 'cksj': $('#Insiders_BrrArchive_cmbCKSJ').combobox('getValue'), 'bname': $('#Insiders_BrrArchive_txtUSERNAME').val()
                                },
                                success: function (data) {
                                    if (data == "1") {
                                        $.messager.alert('提示！', '申请成功!', 'info');
                                        parent.window.ClosewinBrrGrid();
                                    }
                                    else
                                        $.messager.alert('提示！', '申请失败!', 'info');
                                }
                            });
                        }
                    });
                }
                else {
                    lymd = $('#Insiders_BrrArchive_cmbLYMD').combobox("getText");
                    $.ajax({
                        url: '/Insiders/Add_Brr',
                        type: 'post',
                        async: true,
                        dataType: 'text',
                        data: {
                            'entities': JSON.stringify(entities), 'type': @ViewBag.type, 'lymdid': $('#Insiders_BrrArchive_cmbLYMD').combobox("getValue"), 'lymd': lymd, 'YJGUTime': $('#Insiders_BrrArchive_txtYJGHTime').datebox('getValue'),
                                'cksj': $('#Insiders_BrrArchive_cmbCKSJ').combobox('getValue'), 'bname': $('#Insiders_BrrArchive_txtUSERNAME').val()
                        },
                        success: function (data) {
                            if (data == "1") {
                                $.messager.alert('提示！', '申请成功!', 'info');
                                parent.window.ClosewinBrrGrid();
                            }
                            else
                                $.messager.alert('提示！', '申请失败!', 'info');
                        }
                    });
                }
            }
        }
    }
    function formatDel(value, row) {
        return "<a href='javascript:void(0)' onclick='Del(\"" + row.DH + "\")'>取消</a>";
    }

</script>


